/** 字典转选项 */
export function dictToOptions(
  dict: any[],
  fieldNames = { labelKey: 'dictLabel', valueKey: 'dictValue' }
) {
  return dict.map(v => ({
    label: v[fieldNames.labelKey],
    value: v[fieldNames.valueKey]
  }))
}

/** 树形转列表 */
export function treeToList(tree: any, childrenKey = 'children') {
  let queen = []
  const out = []
  queen = queen.concat(tree)

  while (queen.length) {
    const first = queen.shift()
    if (first.children) {
      queen = queen.concat(first.children)
      delete first[childrenKey]
    }
    out.push(first)
  }
  return out
}
